//
//  MoreDetailViewController.m
//  DaDaBao
//
//  Created by user on 15/8/14.
//  Copyright (c) 2015年 User. All rights reserved.
//
#import "MoreDetailViewController.h"
#import "DescribeView.h"
#import "InvestRecordView.h"

@interface MoreDetailViewController ()
@property (nonatomic,strong)DescribeView     * describeView;//描述界面view
@property (nonatomic,strong)InvestRecordView * investRecordView;//投资记录View
@property (nonatomic,strong)NSString *productId;
@property (nonatomic,strong)NSString *productName;
@property(nonatomic,strong)NSArray *nameArr;
@end

@implementation MoreDetailViewController

- (id)initWithProductID:(NSString *)productId andProductName:(NSString *)productName
{
    self = [super init];
    if(self)
    {
        _productId = productId;
        _productName = productName;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    //    自定义navgationBar
    TopView *topView = [[TopView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, SCREEN_HEIGHT, 64.0f)];
    topView.backgroundColor = [UIColor hexStringToColor:COLOR_VALUE];
    
    UIButton *backBtn = [[UIButton alloc]initWithFrame:CGRectMake(0.0f, 20.0f, 64.0f, 44.0f)];
    [backBtn setBackgroundImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(buttonBackTapped:) forControlEvents:UIControlEventTouchUpInside];
    [topView addSubview:backBtn];

    [self.view addSubview:topView];
    
    UISegmentedControl * segment = [[UISegmentedControl alloc]initWithItems:@[@"描述",@"投资记录"]];
    segment.frame = CGRectMake(0, 0, 180.0f, 30.0f);
    segment.center = CGPointMake(self.view.center.x, 42.0f);
    segment.tintColor = [UIColor whiteColor];
    [segment addTarget:self action:@selector(changeTheBackgroundView:) forControlEvents:UIControlEventValueChanged];
    segment.selectedSegmentIndex = 0;
    [self changeTheBackgroundView:segment];
    [topView addSubview:segment];
    
    if (!_nameArr) {
        _nameArr = @[@"用户",@"投资金额",@"投资时间"];
    }
}
//选项卡改变后，切换图
-(void)changeTheBackgroundView:(id)sender
{
    UISegmentedControl * segment = (UISegmentedControl *)sender;
    if (segment.selectedSegmentIndex == 0)
    {
        //创建描述页面
        if (!_describeView)
        {
            _describeView = [[DescribeView alloc]initWithFrame:CGRectMake(0, 64.0f, SCREEN_WIDTH, SCREEN_HEIGHT-64.0f) andProductID:_productId andProductName:_productName];
            _describeView.backgroundColor = [UIColor whiteColor];
            [self.view addSubview:_describeView];
        }
       [self.view bringSubviewToFront:_describeView];
    }else
    {
        //创建投资记录
        if (!_investRecordView)
        {
            _investRecordView = [[InvestRecordView alloc]initWithFrame:CGRectMake(0, 64.0f, SCREEN_WIDTH, SCREEN_HEIGHT-64.0f)andProductID:_productId withUrl:PROJECT_RECOMMEND_LIST_URL nameWithArray:self.nameArr];//需要传数组
            _investRecordView.backgroundColor = [UIColor whiteColor];
            [self.view addSubview:_investRecordView];
        }
        [self.view bringSubviewToFront:_investRecordView];
    }

}
#pragma mark-返回上一页
-(void)buttonBackTapped:(id)sender
{
    [self.navigationController popViewControllerAnimated:TRUE];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
